#include "Timer.h"
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;


#define PRECISION double

void convolve(PRECISION* input, PRECISION* output, PRECISION* filter,  int input_length, int filter_length);
	
int random_value1;
int random_value2;
int input_length;//For this example we will assume that the Input and the Filter have the same length
int filter_length;
PRECISION *input;
PRECISION *filter;
PRECISION *output;

int main()
{
	srand((unsigned)time(0));
	__int64 tStart, tEnd;
    clock_t t;//Creating an instance of the clock

	cout<<"Enter size of vector"<<endl;
	cin>>input_length;
	cout<<"Enter size of filter"<<endl;
	cin>>filter_length;
	tStart = GetTimeus64(); // Get starting time.
	t = clock();  //Starting Clock Ticks 

	//filter_length=input_length;
	input=new PRECISION[input_length];
	filter=new PRECISION[filter_length];
	output= new PRECISION[filter_length];

	srand((unsigned)time(0));
	for (int f=0 ; f<input_length ;f++)
    {
		double X=100;
        random_value1= (double)rand()/((double)RAND_MAX/X);
		input[f]=random_value1;
		cout<<"    "<<input[f]<<"    ";
	}

	cout<<endl;
	//srand((unsigned)time(0));
	for (int g=0; g<filter_length ; g++)
	{

		double X=100;
        random_value2= (double)rand()/((double)RAND_MAX/X);
		filter[g]=random_value2;
		cout<<"    "<<filter[g]<<"    ";
	}
	cout<<endl<<endl<<endl;
	convolve(input, output, filter, input_length, filter_length);
	cout<<endl<<endl<<endl;

	t = clock() - t;        //Calculating total clicks of the clock.
    tEnd = GetTimeus64(); // Get ending time.
    // Difference between starting and ending time in seconds.
    cout << "Time taken = " << ((double)(tEnd-tStart))/(1000000.) << " seconds (High Precision)." << endl;
    cout<<"It took me "<<((double)t)/CLOCKS_PER_SEC<<" seconds (3 dp)."<<endl;

        delete[] input;
        delete[] filter;
        delete[] output;

	return 0;
}




void convolve(PRECISION* input, PRECISION* output, PRECISION* filter,  int input_length, int filter_length)
{
	//output=new PRECISION [filter_length];
    for(int i=0; i<=input_length-filter_length; i++)
	{
        output[i] = 0.0;
        for(int k=0; k<filter_length; k++)
		{
            output[i] += input[i+k] * filter[filter_length - k - 1];
			
			//output[k]=0;
        }
		cout<<"    "<<output[i]<<"    ";
    }
}